const Router = require('koa-router')
const api = require('./api')

const router = new Router()

router.get('/', ctx => {
  ctx.body = {
    msg: '乐清花会管理平台。'
  }
})

router.get('/ip', ctx => {
  ctx.body = {
    ip: ctx.ip
  }
})

router.get('/sign', ctx => {
  log('x')
  ctx.body = makeSign()
})
router.get('/config', ctx => {
  log(ctx.query)
  log('refresh config')
})

router.all('/label', ctx => {
  log(ctx.query)
  log(ctx.request.body)
  var err = {errcode: 1, errmsg: '签名错误'}
  var succ = {value: '测试'}
  ctx.body = (Math.random() - 0.5) > 0 ? succ : err
})

router.get('/set/label', ctx => {
  log(ctx.query)
  ctx.body = {result: 'xxx'}
})

router.get('/gold', ctx => {
  log('refresh gold')
  log(ctx.query)
  ctx.body = {}
})

router.use('/api', api.routes())


module.exports = router
